package
{
	import flash.events.MouseEvent;
	import flash.net.SharedObject;
	
	import ui.Button;
	import ui.List;
	import ui.Panel;

	/**
	 * 删除音乐面板
	 */ 
	public class DelMusicPanel extends Panel
	{
		private	var btnOk:Button = null;
		private	var btnCancel:Button = null;
		private var bgPanel:BgPanel = null;
		
		public function DelMusicPanel(bgPanel:BgPanel)
		{
			super(Asset.getPanelRm());
			this.bgPanel = bgPanel;
			onInit();
		}
		
		public	function	onInit():void{
			this.btnOk = new Button(80, 25, Asset.getButtonDefault());
			this.btnOk.text = "删 除";
			this.btnOk.x = 30;
			this.btnOk.y = this.height - this.btnOk.height - 50;
			this.btnOk.textColor = 0x927E60;
			this.btnOk.textFontSize = 15;
			this.addChild(this.btnOk);
			
			this.btnCancel = new Button(80, 25, Asset.getButtonDefault());
			this.btnCancel.text = "取 消";
			this.btnCancel.x = this.btnOk.getRight()+30;
			this.btnCancel.y = this.btnOk.y;
			this.btnCancel.textColor = 0x927E60;
			this.btnCancel.textFontSize = 15;
			this.addChild(this.btnCancel);
			
			this.btnOk.addEventListener(MouseEvent.CLICK, onOkClick);
			this.btnCancel.addEventListener(MouseEvent.CLICK, onCancelClick);
		}
		
		public	function	onOkClick(evt:MouseEvent):void{
			this.visible = false;
			var list:List = this.bgPanel.getPlayList();
			var index:int = list.getSelectedIndex();
			list.removeItem(index);
			
			//在本地保存播放列表
			var arrItem:Array = list.getItemList();
			var sl:StorageList = new StorageList();
			sl.setItemList(arrItem);
			var so:SharedObject = SharedObject.getLocal("musicPlayer");
			so.data.sl = sl.toString();
			so.flush();
		}
		
		public	function	onCancelClick(evt:MouseEvent):void{
			this.visible = false;
		}		
	}
}